﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ReflectionIT.Silverlight.ReportLibrary;
using System.Windows.Data;

namespace SilverlightReportDemo {

    public partial class MainPage : UserControl {

        public MainPage() {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e) {

            ReportDocument r = new ReportDocument("Test Title");
            r.Header.SubTitle = "Test SubTitle";
            
            // Custom Header!
            r.Header.Style = Application.Current.Resources["ReportHeaderStyle1"] as Style;

            // Stop after 3 pages
            r.PagePrinting += (s, ea) => ea.Cancel = r.Header.PageValue > 3;

            for (int i = 1; i <= 60; i++) {

                var tb = new TextBlock() {
                    Text = "Test text " + i,
                    FontSize = i + 10,
                };

                r.Paragraphs.Add(tb);

                if (i % 36 == 0) {
                    r.Paragraphs.Add(PageBreak.Instance);
                }
            }

            r.Print();
        }

        private void button2_Click(object sender, RoutedEventArgs e) {

            ReportDocument r = new ReportDocument("DataBind Demo");
            r.Header.SubTitle = "Simple Demo using DataBinding";

            string[] l = new string[] {
                "Jim",
                "Ellen",
                "Kim",
                "Mike",
                "James"
            };

            ItemsControl ic = new ItemsControl();
            ic.ItemsSource = l;

            r.Paragraphs.Add(ic);

            r.Print("Demo");

        }

    }
}
